package com.hebada.utils;

import javax.servlet.http.HttpServletRequest;

import org.springframework.util.StringUtils;

/**
 * Created by paddy on 2017/10/8.
 */
public class RequestUtils {

  public static String CONTEXT_PATH;

  public static String setContextPath(HttpServletRequest request) {
    return getContextPath(request);
  }

  private static String getContextPath(HttpServletRequest request) {
    if (StringUtils.isEmpty(CONTEXT_PATH))
      CONTEXT_PATH = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/";
    return CONTEXT_PATH;
  }

  private RequestUtils() {
  }
}
